$(function () {
    window.onload = function () {
        // 大众试用全部
        $.ajax({
            url: 'http://localhost:3000/useing/public',
            type: 'get',
            success: function (tryall) {
                // console.log(tryall);
                var tryarr = ''
                $.each(tryall.slice(0, 12), function (i, ele) {
                    // console.log(ele);
                    if (ele.info_ty === "体验师转享") {
                        tryarr += `<li class="x-new-try">
                        <img class="top-img" src=${ele.img}>
                        <div class="t-title">${ele.text}</div>
                        <div class="t-num">
                            <div class="lv test-num">${ele.totalnum}</div>
                            <div class="test-num lv">${ele.num}台</div>
                        </div>
                        <p>${ele.apply}&nbsp;<span>申请</span></p>
                        <p class="yu green">查看试用名单</p>
                        <div class="start huang">${ele.info_ty}</div>
                    </li>`
                    } else {
                        tryarr += `<li class="x-new-try">
                        <img class="top-img" src=${ele.img}>
                        <div class="t-title">${ele.text}</div>
                        <div class="t-num">
                            <div class="test-num">${ele.totalnum}</div>
                            <div class="test-num">${ele.num}台</div>
                        </div>
                        <p>${ele.apply}&nbsp;<span>申请</span></p>
                        <p class="yu">报告数量：8</p>
                        <div class="start">${ele.info_ty}</div>
                    </li>`
                    }
                })
                $('.total').append(tryarr);
            }
        })
        // 申请中
        $.ajax({
            url: 'http://localhost:3000/useing/master',
            type: 'get',
            success: function (tryall) {
                // console.log(tryall);
                var tryarr = ''
                $.each(tryall, function (i, ele) {
                    // console.log(ele);
                    if (ele.info_ty === "体验师转享") {
                        tryarr += `<li class="x-new-try">
                        <img class="top-img" src=${ele.img}>
                        <div class="t-title">${ele.text}</div>
                        <div class="t-num">
                            <div class="test-num">${ele.totalnum}</div>
                            <div class="test-num">${ele.num}台</div>
                        </div>
                        <p>${ele.apply}&nbsp;<span>申请</span></p>
                        <p class=" yu red">剩余时间两天</p>
                        <div class="start huang">${ele.info_ty}</div>
                    </li>`
                    } else {
                        tryarr += `<li class="x-new-try">
                        <img class="top-img" src=${ele.img}>
                        <div class="t-title">${ele.text}</div>
                        <div class="t-num">
                            <div class="test-num">${ele.totalnum}</div>
                            <div class="test-num">${ele.num}台</div>
                        </div>
                        <p>${ele.apply}&nbsp;<span>申请</span></p>
                        <p class="yu red">查看试用名单</p>
                        <div class="start">${ele.info_ty}</div>
                    </li>`
                    }
                })
                $('.application').append(tryarr);
            }
        })
        // 已结束
        $.ajax({
            url: 'http://localhost:3000/useing/master',
            type: 'get',
            success: function (tryall) {
                // console.log(tryall);
                var tryarr = ''
                $.each(tryall.slice(9, 18), function (i, ele) {
                    // console.log(ele);
                    if (ele.info_ty === "体验师转享") {
                        tryarr += `<li class="x-new-try">
                        <img class="top-img" src=${ele.img}>
                        <div class="t-title">${ele.text}</div>
                        <div class="t-num">
                            <div class="test-num">${ele.totalnum}</div>
                            <div class="test-num">${ele.num}台</div>
                        </div>
                        <p>${ele.apply}&nbsp;<span>申请</span></p>
                        <p class=" yu red">剩余时间两天</p>
                        <div class="start huang">${ele.info_ty}</div>
                    </li>`
                    } else {
                        tryarr += `<li class="x-new-try">
                        <img class="top-img" src=${ele.img}>
                        <div class="t-title">${ele.text}</div>
                        <div class="t-num">
                            <div class="test-num">${ele.totalnum}</div>
                            <div class="test-num">${ele.num}台</div>
                        </div>
                        <p>${ele.apply}&nbsp;<span>申请</span></p>
                        <p class="yu red">查看试用名单</p>
                        <div class="start">${ele.info_ty}</div>
                    </li>`
                    }
                })
                $('.end').append(tryarr);
            }
        })
    }
    // 二级标题页面切换
    $('.znew').on('click', function () {
        $(this).addClass('zre').siblings().removeClass('zre');
        var index = $(this).index();
        $('section').eq(index).show().siblings('section').hide();
        // 默认选中的是全部选项，切换的时候默认也是
        if (index == 0 || 1) {
            // console.log(index);
            $('.tnew').eq(0).addClass('tz').siblings().removeClass('tz');
            $('.huan').eq(0).show().siblings('.huan').hide();
            $('.tyans').eq(0).show().siblings('.tyans').hide();
        }

    })
    // 全部部分页面切换
    $('.tnew').on('click', function () {
        $(this).addClass('tz').siblings().removeClass('tz');
        var index = $(this).index();
        // console.log(index);
        $('.huan').eq(index).show().siblings('.huan').hide();
        $('.tyans').eq(index).show().siblings('.tyans').hide();

    })
    // 页面跳转(事件委托)
    $('.total,.application,.end').on('click', 'li', function () {
        window.location.href = '../use/trynew.html';
    })

})